import axios from 'axios'
// 配置基准路径
const baseURL = 'http://localhost:8888/api/private/v1/'
// 默认基准路径
axios.defaults.baseURL = baseURL

// interceptors  请求拦截器
axios.interceptors.request.use(function (config) {
  // Do something before request is sent
  // 1.获取token
  let token = localStorage.getItem('mytoken')
  // 2.写入请求头
  if (token) {
    config.headers.Authorization = token
  }
  return config
}, function (error) {
  // Do something with request error
  return Promise.reject(error)
})

// 登录
export const login = (params) => {
  return axios.post('login', params).then((res) => {
    return res.data
  })
}

// 请求用户信息
export const getAllUserList = (pa) => {
  return axios.get('users', {params: pa}).then((res) => {
    return res.data
  })
}

// 权限管理界面
export const getMenus = (pa) => {
  return axios.get('menus').then(res => {
    return res.data
  })
}
